home *** CD-ROM | disk | FTP | other *** search
/ STraTOS 1997 April & May / STraTOS 1 - 1997 April & May.iso / CD01 / INTERNET / SITES / GRAHAM / XAAES_S.ZIP / XAAES / MENUBAR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-06  |  7.4 KB  |  320 lines

  1. /*
  2.  * XaAES - XaAES Ain't the AES
  3.  *
  4.  * A multitasking AES replacement for MiNT
  5.  *
  6.  */
  7.  
  8. #include <STRING.H>
  9. #include <VDI.H>
  10. #include <memory.h>
  11. #include "XA_DEFS.H"
  12. #include "XA_TYPES.H"
  13. #include "XA_GLOBL.H"
  14. #include "K_DEFS.H"
  15. #include "RECTLIST.H"
  16. #include "OBJECTS.H"
  17. #include "OBJCWIDG.H"
  18. #include "SYSTEM.H"
  19. #include "C_WINDOW.H"
  20. #include "RESOURCE.H"
  21. #include "RECTLIST.H"
  22.  
  23. /*
  24.     This file provides the interface between XaAES's (somewhat strange) menu
  25.     system and the standard GEM calls. Most GEM apps will only care about the
  26.     menu they install onto the desktop, although XaAES can allow seperate menu's
  27.     for each window.....
  28. */
  29.  
  30. /*
  31.     Install a menu bar onto the desktop window
  32. */
  33. unsigned long XA_menu_bar(short clnt_pid, AESPB *pb)
  34. {
  35.     XA_RECT_LIST *drl;
  36.     XA_RECT_LIST *rl;
  37.     XA_WIDGET_TREE *menu_bar=(XA_WIDGET_TREE*)(root_window->widgets[XAW_MENU].stuff);
  38.     
  39.     pb->intout[0]=1;
  40.     
  41.     switch(pb->intin[0])
  42.     {
  43.         case MENU_INSTALL:
  44.             fix_menu((OBJECT*)pb->addrin[0]);    /* do a special fix on menu the menu  */
  45.             clients[clnt_pid].std_menu=(OBJECT*)pb->addrin[0];
  46.             menu_bar->tree=(OBJECT*)(pb->addrin[0]);
  47.             menu_bar->owner=clnt_pid;
  48.  
  49. #if JOHAN_RECTANGLES
  50.             if (!(rl = root_window->rl_full))
  51.                 rl = root_window->rl_full = generate_rect_list(root_window);
  52. #else
  53.             rl=generate_rect_list(root_window);
  54. #endif
  55.  
  56.             v_hide_c(V_handle);
  57.             while(rl)
  58.             {
  59.                 drl=rl;
  60.                 set_clip(rl->x, rl->y, rl->w, rl->h);
  61.                 display_menu_widget(root_window, &root_window->widgets[XAW_MENU]);
  62.                 rl=rl->next;
  63. #if JOHAN_RECTANGLES
  64. #else
  65.                 free(drl);
  66. #endif
  67.             }
  68.             clear_clip();
  69.             v_show_c(V_handle,1);
  70.             
  71.             break;
  72.         case MENU_REMOVE:
  73.             clients[clnt_pid].std_menu=ResourceTree(system_resources,SYSTEM_MENU);
  74.             menu_bar->owner=AESpid;
  75.             menu_bar->tree=clients[clnt_pid].std_menu;
  76.         
  77. #if JOHAN_RECTANGLES
  78.             if (!(rl = root_window->rl_full))
  79.                 rl = root_window->rl_full = generate_rect_list(root_window);
  80. #else
  81.             rl=generate_rect_list(root_window);
  82. #endif        
  83.             v_hide_c(V_handle);
  84.             while(rl)
  85.             {
  86.                 drl=rl;
  87.                 set_clip(rl->x, rl->y, rl->w, rl->h);
  88.                 display_menu_widget(root_window, &root_window->widgets[XAW_MENU]);
  89.                 rl=rl->next;
  90. #if JOHAN_RECTANGLES
  91. #else
  92.                 free(drl);
  93. #endif
  94.             }
  95.             clear_clip();
  96.             v_show_c(V_handle,1);
  97.             break;
  98.             
  99.         case MENU_INQUIRE:
  100.             pb->intout[0]=menu_bar->owner;
  101.             break;
  102.     }
  103.     
  104.     return XAC_DONE;
  105. }
  106.  
  107. /*
  108.     Highlight / un-highlight a menu title
  109.     -actually, this isn't really needed as XaAES cancels the highlight itself....
  110.     ...it's only here for compatibility. 
  111. */
  112. unsigned long XA_menu_tnormal(short clnt_pid, AESPB *pb)
  113. {
  114.     XA_WIDGET_TREE *menu_bar=(XA_WIDGET_TREE*)(root_window->widgets[XAW_MENU].stuff);
  115.     OBJECT *tree=(OBJECT*)pb->addrin[0];
  116.     
  117.     if (pb->intin[1])            /* Change the highlight / normal status of a menu title */
  118.         tree[pb->intin[0]].ob_state&=~SELECTED;
  119.     else
  120.         tree[pb->intin[0]].ob_state|=SELECTED;
  121.     
  122. /* If we just changed the main root window's menu, better redraw it */
  123.     if ((tree==menu_bar->tree)&&(tree[pb->intin[0]].ob_type==G_TITLE))
  124.     {
  125. #if JOHAN_RECTANGLES
  126.         XA_RECT_LIST *rl, *drl;
  127. #else
  128.         XA_RECT_LIST *drl;
  129.         XA_RECT_LIST *rl=generate_rect_list(root_window);
  130. #endif
  131.  
  132. #if JOHAN_RECTANGLES
  133.         if (!(rl = root_window->rl_full))
  134.             rl = root_window->rl_full = generate_rect_list(root_window);
  135. #endif
  136.  
  137.         v_hide_c(V_handle);
  138.         while(rl)
  139.         {
  140.             drl=rl;
  141.             set_clip(rl->x, rl->y, rl->w, rl->h);
  142.             display_menu_widget(root_window, &root_window->widgets[XAW_MENU]);
  143.             rl=rl->next;
  144. #if JOHAN_RECTANGLES
  145. #else
  146.             free(drl);
  147. #endif
  148.         }
  149.         clear_clip();
  150.         v_show_c(V_handle,1);
  151.     }
  152.     
  153.     pb->intout[0]=1;
  154.     
  155.     return XAC_DONE;
  156. }
  157.  
  158. /*
  159.     Enable/Disable a menu item
  160. */
  161. unsigned long XA_menu_ienable(short clnt_pid, AESPB *pb)
  162. {
  163.     XA_WIDGET_TREE *menu_bar=(XA_WIDGET_TREE*)(root_window->widgets[XAW_MENU].stuff);
  164.     OBJECT *tree=(OBJECT*)pb->addrin[0];
  165.     
  166.     if (pb->intin[1])            /* Change the disabled status of a menu item */
  167.         tree[pb->intin[0]].ob_state&=~DISABLED;
  168.     else
  169.         tree[pb->intin[0]].ob_state|=DISABLED;
  170.     
  171. /* If we just changed the main root window's menu, better redraw it */
  172.     if ((tree==menu_bar->tree)&&(tree[pb->intin[0]].ob_type==G_TITLE))
  173.     {
  174. #if JOHAN_RECTANGLES
  175.         XA_RECT_LIST *rl, *drl;
  176. #else
  177.         XA_RECT_LIST *drl;
  178.         XA_RECT_LIST *rl=generate_rect_list(root_window);
  179. #endif
  180.  
  181. #if JOHAN_RECTANGLES
  182.         if (!(rl = root_window->rl_full))
  183.             rl = root_window->rl_full = generate_rect_list(root_window);
  184. #endif
  185.  
  186.         v_hide_c(V_handle);
  187.         while(rl)
  188.         {
  189.             drl=rl;
  190.             set_clip(rl->x, rl->y, rl->w, rl->h);
  191.             display_menu_widget(root_window, &root_window->widgets[XAW_MENU]);
  192.             rl=rl->next;
  193. #if JOHAN_RECTANGLES
  194. #else
  195.             free(drl);
  196. #endif
  197.         }
  198.         clear_clip();
  199.         v_show_c(V_handle,1);
  200.     }
  201.     pb->intout[0]=1;
  202.  
  203.     return XAC_DONE;
  204. }
  205.  
  206. /*
  207.     Check / un-check a menu item
  208. */
  209. unsigned long XA_menu_icheck(short clnt_pid, AESPB *pb)
  210. {
  211.     XA_WIDGET_TREE *menu_bar=(XA_WIDGET_TREE*)(root_window->widgets[XAW_MENU].stuff);
  212.     OBJECT *tree=(OBJECT*)pb->addrin[0];
  213.     
  214.     if (pb->intin[1])            /* Change the disabled status of a menu item */
  215.         tree[pb->intin[0]].ob_state|=CHECKED;
  216.     else
  217.         tree[pb->intin[0]].ob_state&=~CHECKED;
  218.     
  219. /* If we just changed the main root window's menu, better redraw it */
  220.     if ((tree==menu_bar->tree)&&(tree[pb->intin[0]].ob_type==G_TITLE))
  221.     {
  222. #if JOHAN_RECTANGLES
  223.         XA_RECT_LIST *rl, *drl;
  224. #else
  225.         XA_RECT_LIST *drl;
  226.         XA_RECT_LIST *rl=generate_rect_list(root_window);
  227. #endif
  228.  
  229. #if JOHAN_RECTANGLES
  230.         if (!(rl = root_window->rl_full))
  231.             rl = root_window->rl_full = generate_rect_list(root_window);
  232. #endif        
  233.         v_hide_c(V_handle);
  234.         while(rl)
  235.         {
  236.             drl=rl;
  237.             set_clip(rl->x, rl->y, rl->w, rl->h);
  238.             display_menu_widget(root_window, &root_window->widgets[XAW_MENU]);
  239.             rl=rl->next;
  240. #if JOHAN_RECTANGLES
  241. #else
  242.             free(drl);
  243. #endif
  244.         }
  245.         clear_clip();
  246.         v_show_c(V_handle,1);
  247.     }
  248.     
  249.     pb->intout[0]=1;
  250.  
  251.     return XAC_DONE;
  252. }
  253.  
  254. /*
  255.     Change a menu item's text
  256. */
  257. unsigned long XA_menu_text(short clnt_pid, AESPB *pb)
  258. {
  259.     XA_WIDGET_TREE *menu_bar=(XA_WIDGET_TREE*)(root_window->widgets[XAW_MENU].stuff);
  260.     OBJECT *tree=(OBJECT*)pb->addrin[0];
  261.     char *text=(char*)pb->addrin[1];
  262.     
  263.     strcpy((char*)tree[pb->intin[0]].ob_spec,text);
  264.     
  265. /* If we just changed the main root window's menu, better redraw it */
  266.     if ((tree==menu_bar->tree)&&(tree[pb->intin[0]].ob_type==G_TITLE))
  267.     {
  268. #if JOHAN_RECTANGLES
  269.         XA_RECT_LIST *rl, *drl;
  270. #else
  271.         XA_RECT_LIST *drl;
  272.         XA_RECT_LIST *rl=generate_rect_list(root_window);
  273. #endif
  274.  
  275. #if JOHAN_RECTANGLES
  276.         if (!(rl = root_window->rl_full))
  277.             rl = root_window->rl_full = generate_rect_list(root_window);
  278. #endif
  279.  
  280.         v_hide_c(V_handle);
  281.         while(rl)
  282.         {
  283.             drl=rl;
  284.             set_clip(rl->x, rl->y, rl->w, rl->h);
  285.             display_menu_widget(root_window, &root_window->widgets[XAW_MENU]);
  286.             rl=rl->next;
  287. #if JOHAN_RECTANGLES
  288. #else
  289.             free(drl);
  290. #endif
  291.         }
  292.         clear_clip();
  293.         v_show_c(V_handle,1);
  294.     }
  295.     
  296.     pb->intout[0]=1;
  297.  
  298.     return XAC_DONE;
  299. }
  300.  
  301. /*
  302.     Register an apps 'pretty' & 'official' names.
  303. */
  304. unsigned long XA_menu_register(short clnt_pid, AESPB *pb)
  305. {
  306.     short f;
  307.     
  308.     if (pb->intin[0]!=-1)
  309.     {
  310.         strcpy(clients[clnt_pid].name,(char*)pb->addrin[0]);
  311.     }else{
  312.         strncpy(clients[clnt_pid].proc_name,(char*)pb->addrin[0],8);
  313.         for(f=strlen(clients[clnt_pid].proc_name); f<8; f++)
  314.             clients[clnt_pid].proc_name[f]=' ';
  315.         clients[clnt_pid].proc_name[8]='\0';
  316.     }
  317.     
  318.     return XAC_DONE;
  319. }
  320.